#!/bin/bash
#Onekey install tomcat7 for centos6.x
#author merci

#tomcat部署目录
TOMCATDIR='/usr/local/'

checkJdk=`rpm -qa | grep 'java'`
if [ ! $checkJdk ]
then
    yum install  java-1.7.0-openjdk.x86_64 java-1.7.0-openjdk-devel.x86_64 -y
else
    yum remove java* -y
    yum install  java-1.7.0-openjdk.x86_64 java-1.7.0-openjdk-devel.x86_64 -y  
fi

wget http://mirrors.shu.edu.cn/apache/tomcat/tomcat-7/v7.0.88/bin/apache-tomcat-7.0.88.tar.gz
tar -zxvf apache-tomcat-7.0.88.tar.gz
mv apache-tomcat-7.0.88 ${TOMCATDIR}/tomcat7
chmod -R +x ${TOMCATDIR}/tomcat7/bin
touch /etc/rc.d/init.d/tomcat
cat > /etc/rc.d/init.d/tomcat << EOF
#!/bin/bash
#
# /etc/rc.d/init.d/tomcat
# init script for tomcat precesses
#
# processname: tomcat
# description: tomcat is a j2se server
# chkconfig: 2345 86 16
# description: Start up the Tomcat servlet engine.
if [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
else
echo -e "\atomcat: unable to locate functions lib. Cannot continue."
exit -1
fi
RETVAL=\$?
CATALINA_HOME="${TOMCATDIR}tomcat7" #tomcat安装目录
case "\$1" in
start)
if [ -f \$CATALINA_HOME/bin/startup.sh ];
then
echo \$"Starting Tomcat"
\$CATALINA_HOME/bin/startup.sh
fi
;;
stop)
if [ -f \$CATALINA_HOME/bin/shutdown.sh ];
then
echo \$"Stopping Tomcat"
\$CATALINA_HOME/bin/shutdown.sh
fi
;;
*)
echo \$"Usage: \$0 {start|stop}"
exit 1
;;
esac
exit \$RETVAL
EOF
chmod 755 /etc/rc.d/init.d/tomcat
chkconfig --add tomcat
chkconfig tomcat on
echo -e "Tomcat7 install successfly !"